@using Orientation = Radzen.Orientation
@using Elsa.Api.Client.Resources.WorkflowInstances.Enums

<RadzenSplitter Orientation="Orientation.Vertical" Style="height: calc(100vh - var(--mud-appbar-height));" Resize="@OnResize">
    <RadzenSplitterPane Size="50%">
        @if (WorkflowDefinition != null && WorkflowInstance != null!)
        {
            <DiagramDesignerWrapper @ref="_designer" Activity="WorkflowDefinition.Root" ActivitySelected="OnActivitySelected" IsReadOnly="true" WorkflowInstanceId="@WorkflowInstance.Id" PathChanged="PathChanged">
                <CustomToolbarItems>
                    <MudTooltip Text="Edit Workflow Definition">
                        <MudIconButton
                            Icon="@Icons.Material.Outlined.EditNote"
                            OnClick="@(() => OnEditClicked(WorkflowDefinition.DefinitionId))">
                        </MudIconButton>
                    </MudTooltip>
                    <ElapsedTime StartTime="WorkflowInstance.CreatedAt" EndTime="@(WorkflowInstance.Status == WorkflowStatus.Running ? DateTimeOffset.UtcNow : WorkflowInstance.FinishedAt ?? DateTimeOffset.UtcNow)"/>
                </CustomToolbarItems>
            </DiagramDesignerWrapper>
        }
    </RadzenSplitterPane>
    <RadzenSplitterPane Size="30%" @ref="ActivityPropertiesPane">
        <CascadingValue Value="_activityNodeLookup">
            @if (SelectedWorkflowExecutionLogRecord != null || SelectedActivity != null)
            {
                <MudTabs Elevation="0" ApplyEffectsToContainer="true" @ref="PropertyTabs">
                    @if (SelectedWorkflowExecutionLogRecord != null)
                    {
                        <MudTabPanel Text="Event" @ref="EventsTabPanel">
                            <JournalEntryDetailsTab VisiblePaneHeight="@_propertiesPaneHeight" JournalEntry="SelectedWorkflowExecutionLogRecord"/>
                        </MudTabPanel>
                    }

                    @if (SelectedActivity != null)
                    {
                        <MudTabPanel Text="Activity">
                            <ActivityDetailsTab Activity="@SelectedActivity" ActivityExecutions="SelectedActivityExecutions" VisiblePaneHeight="@_propertiesPaneHeight"/>
                        </MudTabPanel>

                        <MudTabPanel Text="Executions" BadgeData="@SelectedActivityExecutions.Count">
                            <ActivityExecutionsTab Activity="@SelectedActivity" ActivityExecutions="SelectedActivityExecutions" VisiblePaneHeight="@_propertiesPaneHeight"/>
                        </MudTabPanel>
                    }

                </MudTabs>
            }
        </CascadingValue>
    </RadzenSplitterPane>
</RadzenSplitter>